<!--头部公共部分-->
{include file="common/header" /}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane">
                <fieldset class="layui-elem-field layui-field-title">
                </fieldset>
                <div class="layui-form-item">
                    <p>
                        {$count}个客户将被转为学员，并且无法恢复，确认转为学员吗?
                    </p>
                </div>
                <fieldset class="layui-elem-field layui-field-title">
                </fieldset>
                <div class="layui-row layui-form-item">
                    <div class="layui-input-block" style="float: right;">
                        <input type="hidden" id="ids" name="ids" value="{$ids}">
                        <input type="hidden" id="campus_id" name="campus_id" value="{$campus_id}">
                        <input type="hidden" name="is_audition" value="2">
                        <a class="layui-btn layui-btn-primary" data-type="cancel">取消</a>
                        <!--
                        <button class="layui-btn" lay-submit="" lay-filter="form-organization-add">确认</button>
                        -->
                        {if $count == 1}
                        <a class="layui-btn layui-btn-normal" id="sign_up">报名</a>
                        {else/}
                        {/if}
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    layui.use(['table','element','form', 'layer'], function () {
        let table = layui.table,
            form = layui.form,
            layer = layui.layer,
            element = layui.element,
            $ = layui.$;
        let campus_id = '{$campus_id}'; // 校区ID
        form.on('submit(form-organization-add)', function (data) {
            console.log(data.field);
            $.ajax({
                url: "{:url('Customer/formalStudent')}",
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (res) {
                    if (res.code === 1) {
                        layer.msg(res.msg, {icon: 1, time: res.wait * 1000}, function () {
                            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: res.wait * 1000}, function () {
                        });
                    }
                },
            });
            return false;
        });

        $("#sign_up").click(function () {
            let id = $("#ids").val();
            //报名
            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
            $.ajax({
                url: '{:url("Customer/delete_invalid_contract")}',
                method: "post",
                success: function (result) {
                    if (result.code === 1) {
                        parent.location.href = '{:url("Customer/course_contract")}?student_id='+id+'&type='+ '{$type}' + '&campus_id=' + campus_id;
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });

        })

        let active = {
            cancel: function () {
                let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            },
            reload: function () {
                window.location.reload();
            }
        };

        $('.layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
